<script src="script/my_lightbox.js"></script>
<div class="path">
  <div> <a href="main.php?cg_u_type=2">卖家中心</a> <span>&gt;</span> <a href="main.php?m=logistics&s=admin_logistics_temp">物流工具</a> <span>&gt;</span> 物流工具 </div>
</div>
<div class="main">
  <div class="wrap">
    <div class="hd">
      <ul class="tabs">
        <li class="active"><a href="main.php?m=logistics&s=admin_logistics_temp">运费模板</a></li>
      </ul>
      <a href="main.php?m=logistics&s=admin_logistics_temp&type=add" class="btn3">新增运费模板 </a> </div>
    <{if $smarty.get.type=='add'}>
    <div class="form-style">
      <form action="" method="post">
        <input name="action" type="hidden" id="action" value="submit" />
        <dl>
          <dt><em>*</em>模板名称：</dt>
          <dd>
            <input value="<{$de.title}>" name="title" type="text" id="title" class="w150 text" />
          </dd>
        </dl>
        <dl>
          <dt>计价方式：</dt>
          <dd>
            <input onclick="cg_type(this.value);" name="price_type" value="件" data-type="number" type="radio" checked="checked"  />
            <label> 按件数</label>
            <input onclick="cg_type(this.value);" name="price_type" <{if $de.price_type=='kg'}>checked="checked"<{/if}> value="kg" data-type="weight" type="radio" />
            <label> 按重量</label>
            <input onclick="cg_type(this.value);" name="price_type" <{if $de.price_type=='m³'}>checked="checked"<{/if}> value="m³" data-type="volume" type="radio" />
            <label> 按体积</label>
          </dd>
        </dl>
        <dl>
          <dt>运送方式：</dt>
          <dd>
            <p> <{foreach item=list key=num from=$config.lgs_type}>
              <label onclick="show_lgs_con('<{$num}>');">
              <input id="<{$num}>" class="checkbox" name="" type="checkbox" value="" />
              <{$list}> </label>
            <div id="<{$num}>_con"></div>
            <{/foreach}>
            </p>
            <p class="hint">除指定地区外，其余地区的运费采用“默认运费”</p>
          </dd>
        </dl>
        <dl class="foot">
          <dt>&nbsp;</dt>
          <dd>
            <input type="submit" name="submit" value="<{$lang.submit}>" class="submit">
          </dd>
        </dl>
      </form>
    </div>
    <div style="display:none;" id="lgs_box_con">
      <div style="border:1px solid #999999; padding:10px;">
        <table background="#F3FEED" width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td align="left" bgcolor="#F3FEED">&nbsp;
              默认运费：
              <input type="text" style="width:50px;" id="default_type_num" name="default_type_num[]" value="1" />
              unit内，
              <input style="width:50px;" id="default_type_price" name="default_type_price[]" type="text" />
              元， 每增加
              <input style="width:50px;" id="add_type_num" name="add_type_num[]" type="text" />
              unit， 增加运费
              <input style="width:50px;" id="add_type_price" name="add_type_price[]" type="text" />
              元
              <input name="add_type_city[]" type="hidden" value="default" />
            </td>
          </tr>
        </table>
        <div style="margin-top:10px;">
          <table style="display:none; border-collapse:separate; border-spacing:1px;" id="define_table_type" width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#BBBBBB">
            <tr>
              <td width="220" align="center" bgcolor="#F5F5F5">运送到</td>
              <td align="center" bgcolor="#F5F5F5">起始(unit)</td>
              <td align="center" bgcolor="#F5F5F5">起始费(元)</td>
              <td align="center" bgcolor="#F5F5F5">每增(unit)</td>
              <td align="center" bgcolor="#F5F5F5">续费(元)</td>
              <td align="center" bgcolor="#F5F5F5">操作</td>
            </tr>
            <tr id="tr0_type">
              <td align="left" bgcolor="#FFFFFF"><input id="add_type_city_tr0" name="add_type_city[]" type="hidden" />
                <span id="add_type_city_tr0_span"></span> <a style="color:#3366CC; float:right;" href="javascript:open_box('add_type_city_tr0');"><{$lang.edit}></a> </td>
              <td align="center" bgcolor="#FFFFFF"><input style="width:50px;" id="default_type_num_tr0" name="default_type_num[]" type="text" /></td>
              <td align="center" bgcolor="#FFFFFF"><input style="width:50px;" id="default_type_price_tr0" name="default_type_price[]" type="text" /></td>
              <td align="center" bgcolor="#FFFFFF"><input style="width:50px;" id="add_type_num_tr0" name="add_type_num[]" type="text" /></td>
              <td align="center" bgcolor="#FFFFFF"><input style="width:50px;" id="add_type_price_tr0" name="add_type_price[]" type="text" /></td>
              <td align="center" bgcolor="#FFFFFF"><a style="color:#3366CC;" href="javascript:remove_tr('tr0','_type');"><{$lang.delete}></a></td>
            </tr>
          </table>
        </div>
        <a href="javascript:add_tr('_type');">为指定地区城市设置运费</a> </div>
    </div>
    <div id="pv_box" style="display:none;">
    <{foreach item=list key=num from=$pv}>
      <li class="prov"  id="pv_<{$num}>_li">
        <input name="provs[]" id="pv_<{$num}>" onclick="show_city('pv_<{$num}>','all');" type="checkbox" value="" />
        <{$list.name}><span style="color:#FF6600;" id="pv_<{$num}>_cn"></span><a href="javascript:show_city2('pv_<{$num}>');"><img src="image/default/arw_r.gif" /></a>
        <div> <{foreach item=slist key=cnum from=$list.city}>
          <input class="all_city_input" name="pv_<{$num}>_citys[]" type="checkbox" value="<{$slist.name}>" />
          <{$slist.name}>
          <{/foreach}> <br />
          <input class="btn" onclick="close_city('pv_<{$num}>','<{$cnum}>');" value="关闭" name="" type="button" />
        </div>
      </li>
      <{/foreach}>
      <div style="float:left; width:100%;">
        <input onclick="add_city();" class="btn" value="确定" name="" type="button" />
      </div>
    </div>
    <{else}>
	
    <{foreach item=list from=$lglist}>
    <table style="border-collapse:separate; border-spacing:1px; margin-top:10px;" width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#BBBBBB">
      <tr>
        <td colspan="6" bgcolor="#E8F2FF"><span style="float:left; font-weight:bold; padding-left:5px;"><{$list.title}></span> <span style="float:right;"><a href="main.php?m=logistics&s=admin_logistics_temp&deid=<{$list.id}>">删除</a> <a href="main.php?m=logistics&s=admin_logistics_temp&type=add&edit=<{$list.id}>">编辑</a></span> </td>
      </tr>
      <tr>
        <td width="10%" align="center" bgcolor="#E8F2FF">运送方式</td>
        <td align="center" bgcolor="#E8F2FF">运送到</td>
        <td width="10%" align="center" bgcolor="#E8F2FF">起始(<{$list.price_type}>)</td>
        <td width="10%" align="center" bgcolor="#E8F2FF">费用(元)</td>
        <td width="10%" align="center" bgcolor="#E8F2FF">每增(<{$list.price_type}>)</td>
        <td width="10%" align="center" bgcolor="#E8F2FF">费用(元)</td>
      </tr>
      <{foreach item=slist from=$list.detail}>
      <tr>
        <td align="center" bgcolor="#FFFFFF"><{if $slist.logistics_type=='mail'}>平邮<{elseif $slist.logistics_type=='express'}>快递<{else}>EMS<{/if}></td>
        <td align="left" bgcolor="#FFFFFF"><{if $slist.define_citys=='default'}><b>全国</b><{else}><{$slist.define_citys}><{/if}></td>
        <td align="center" bgcolor="#FFFFFF"><{$slist.default_num}></td>
        <td align="center" bgcolor="#FFFFFF"><{$slist.default_price|number_format:2}></td>
        <td align="center" bgcolor="#FFFFFF"><{$slist.add_num}></td>
        <td align="center" bgcolor="#FFFFFF"><{$slist.add_price|number_format:2}></td>
      </tr>
      <{/foreach}>
    </table>
    <{/foreach}>
    <{/if}> </div>
</div>
<{if $smarty.get.type==add}>
<style>
.prov{display:block; float:left; width:90px; margin-left:8px; margin-top:8px;}
.prov div{background-color:#FFFEC6; border:1px solid #F7E4A5;position:absolute; z-index:100000; width:300px; display:none; padding:2px;}
</style>
<script>
	var ctr=0;
	var sca=new Array();
	var temp_str='';
	function open_box(tr)
	{
		var obj=document.getElementById('pv_box');
		if(obj.innerHTML==''&&temp_str!='')
			obj.innerHTML=temp_str;
		else
			temp_str=obj.innerHTML;
			
		alertWin('选择城市',obj,'500','400');
		ctr=tr;//当前的列
		sca=new Array();//将上次选的值清空
	}
	
	function add_city()
	{
		ins=$('.all_city_input');
		for(var k in  ins)
		{
			if(ins[k].checked==true)
				sca.push(ins[k].value)
		}
		document.getElementById(ctr).value=sca;
		document.getElementById(ctr+'_span').innerHTML=sca;
		document.getElementById('pv_box').innerHTML=temp_str;
		close_win();
	}
	
	function count_city(id)
	{
		t=0;
		provs=$("input[name='"+id+"_citys[]']");
		for( var i in provs )
		{
			if(provs[i].checked)
				t++;
		}
		return t;
	}
	
	function close_city(id,all_city_num)
	{
		$('#'+id+'_li div').hide();
		$('#'+id+'_li').css('background-color','#FFFFFF');
		select_citys=count_city(id);
		$('#'+id+'_cn').html('('+select_citys+')');
		if(select_citys-1==all_city_num)
			$('#'+id).attr("checked",true);
		else
			$('#'+id).attr("checked",false);
	}
	
	function show_city(id)
	{

		$('.prov div').hide();
		$('.prov').css("background-color","#FFFFFF");
		
		if($('#'+id).attr("checked"))
		{
			$('#'+id+'_li input').attr("checked",true);
			$('#'+id+'_cn').html('('+count_city(id)+')');
		}
		else
		{
			$('#'+id+'_cn').html('');
			$('#'+id+'_li input').attr("checked",false);
		}
	}
	
	function show_city2(id)
	{
		$('.prov div').hide();
		$('.prov').css("background-color","#FFFFFF");
		
		$('#'+id+'_li div').show();
		$('#'+id+'_li').css("background-color","#F7E4A5");
	}


	units='件';
	<{if $de.price_type}>
		units='<{$de.price_type}>';
	<{/if}>
	function cg_type(type)
	{
		units=type;
		$('#express_con').html('');
		$('#ems_con').html('');
		$('#mail_con').html('');
		
		$('#express').attr("checked",false);
		$('#ems').attr("checked",false);
		$('#mail').attr("checked",false);
	}
	
	function show_lgs_con(id)
	{
		if($('#'+id).attr("checked")==true)
		{
			con=$('#lgs_box_con').html().replaceAll('_type','_'+id);
			con=con.replaceAll('unit',units);
			$('#'+id+'_con').html(con);
		}
		else
		{
			$('#'+id+'_con').html('');
		}
	}
	
	function add_tr(type)
	{
		if($('#define_table'+type).css('display') == 'none')
			$('#define_table'+type).show();
		else
		{
			i=$('#define_table'+type+' tr').length-1;
			var tr1="<tr id='tr"+i+type+"'>";
			var tr2=$('#tr0'+type).html().replaceAll('tr0','tr'+i);
			    tr2=tr2.replaceAll('unit',units);
				var tr3="</tr>";
				$('#define_table'+type).append(tr1+tr2+tr3);
				$('#add'+type+'_city_tr'+i+'_span').html('');
				
		}
	}
	
	function remove_tr(row,table)
	{
		if(row=='tr0')
		{
			$('#define_table'+table).hide();
			$('#add'+table+'_price_tr0').val('');
			$('#add'+table+'_num_tr0').val('');
			
			$('#default'+table+'_price_tr0').val('');
			$('#default'+table+'_num_tr0').val('');
		}
		else
			$('#'+row+table).remove();
	}
	
	String.prototype.replaceAll = function (str1,str2)
	{
	  var str    = this;     
	  var result   = str.replace(eval("/"+str1+"/gi"),str2);
	  return result;
	}
	
	function set_default_value(v1,v2,v3,v4,type)
	{
		$('#default_'+type+'_num').val(v1);
		$('#default_'+type+'_price').val(v2);
		$('#add_'+type+'_num').val(v3);
		$('#add_'+type+'_price').val(v4);
	}
	
	function set_tr_value(type,i,v1,v2,v3,v4,v5)
	{
		$('#default_'+type+'_num_tr'+i).val(v1);
		$('#default_'+type+'_price_tr'+i).val(v2);
		$('#add_'+type+'_num_tr'+i).val(v3);
		$('#add_'+type+'_price_tr'+i).val(v4);
		$('#add_'+type+'_city_tr'+i).val(v5);
		$('#add_'+type+'_city_tr'+i+'_span').html(v5);
	}
	
	/**打开自定义窗口**/
	<{foreach item=list from=$de.logistics_default}>
		$('#<{$list.logistics_type}>').attr("checked",true);
		show_lgs_con('<{$list.logistics_type}>');
		set_default_value('<{$list.default_num}>','<{$list.default_price}>','<{$list.add_num}>','<{$list.add_price}>','<{$list.logistics_type}>')
	<{/foreach}>
	
	/**初始化自定义**/
	<{foreach item=list key=num from=$de.detail}>
		<{foreach item=slist key=snum from=$list}>
			add_tr('_<{$num}>');
			set_tr_value('<{$num}>','<{$snum}>','<{$slist.default_num}>','<{$slist.default_price}>','<{$slist.add_num}>','<{$slist.add_price}>','<{$slist.define_citys}>');
		<{/foreach}>
	<{/foreach}>
	
</script>
<{/if}>